package com.anmong.cloud.cloudadmin.controller;


import com.anmong.cloud.cloudadmin.service.TestSysUserService;
import com.anmong.cloud.cloudapi.base.BasePageDTO;
import com.anmong.cloud.cloudapi.dto.TestUpdateDTO;
import com.anmong.cloud.cloudapi.entity.SysUser;
import com.anmong.cloud.cloudapi.mapper.SysUserMapper;
import com.anmong.cloud.cloudcommon.exception.CommonException;
import com.anmong.cloud.cloudcommon.response.R;
import com.anmong.cloud.cloudcommon.util.PageUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("test")
@Tag(name = "测试接口", description = "测试接口")
public class TestController {

    @Autowired
    private TestSysUserService testSysUserService;
    @Autowired
    private SysUserMapper sysUserMapper;

    @GetMapping("test")
    @Operation(summary = "测试接口聚合", description = "测试接口聚合")
    public String getId(){
        return String.valueOf("hello swagger");
    }

    @PutMapping("update")
    @Operation(summary = "测试更新库", description = "测试插入数据库")
    public R update(@RequestBody @Valid TestUpdateDTO dto){
       return R.collectionItem(testSysUserService.testUpdate(dto));
    }

    @GetMapping("list")
    @Operation(summary = "测试feign返回list类型解码", description = "测试接口聚合")
    public R list(){
        return R.collection(testSysUserService.list());
    }

    @GetMapping("empty")
    @Operation(summary = "测试feign返回空值类型解码", description = "测试接口聚合")
    public R empty(){
        testSysUserService.empty();
        return R.ok();
    }

    @GetMapping("sysuser/{id}")
    @Operation(summary = "测试restfull风格查询系统用户", description = "测试接口聚合")
    public R findById(@PathVariable Long id){
        return R.collectionItem(testSysUserService.findById(id));
    }

    @GetMapping("page")
    @Operation(summary = "测试分页", description = "测试插入数据库")
    public R page(BasePageDTO dto){
        IPage<SysUser> page = sysUserMapper.selectPage(new Page<SysUser>(dto.getPage(),dto.getSize())
                ,new QueryWrapper<SysUser>()
        );

        return R.page(new PageUtils(page));
    }


}
